package edu.exp3.model;

import java.util.ArrayList;

public class Student extends Person {
    // 学生可选多门课
    private ArrayList<Course> courses = new ArrayList<Course>();

    public Student(String id, String name, Gender gender) {
        super(id, name, gender); // super() 初始化父类字段
    }

    public boolean selectCourse(Course c) {
        if (c == null) return false;
        if (courses.contains(c)) {
            System.out.println(name + "选课失败（已选过）：" + c.getName());
            return false;
        }
        boolean ok = c.enroll(this);
        if (ok) {
            courses.add(c);
            System.out.println(name + "选课成功：" + c.getName());
        } else {
            System.out.println(name + "选课失败（容量满或其他原因）：" + c.getName());
        }
        return ok;
    }

    public boolean dropCourse(Course c) {
        if (c == null) return false;
        boolean ok = c.drop(this);
        if (ok) {
            courses.remove(c);
            System.out.println(name + "已退课：" + c.getName());
        } else {
            System.out.println(name + "退课失败（未选该课）：" + c.getName());
        }
        return ok;
    }

    public ArrayList<Course> getCourses() {
        return new ArrayList<Course>(courses);
    }

    @Override
    public void printWorkSheet() {
        System.out.println("=== 学生课表 ===");
        System.out.println(baseInfo());
        if (courses.isEmpty()) {
            System.out.println("暂无选课记录");
        } else {
            for (Course c : courses) {
                System.out.println("已选课程：" + c.getName());
                System.out.println("上课地点：" + c.getPlace());
                System.out.println("上课时间：" + c.getTime());
                System.out.println("授课教师：" + c.getTeacher().getName());
                System.out.println("---");
            }
        }
    }
}
